import {Component} from "react";
import {Table} from "antd";
import "./ Calculator.css"

class History extends Component {
    constructor(props) {
        super(props);
    }
    reCalculator = (record) => {
        let reList = ""
        reList = record.split(" ").slice(0, -2)
        reList = reList.join(" ")
        this.props.reCalculator(reList)
    }
    childDelete = (record) => {
        this.props.handleDelete(record)
    }
    columns = [
        {
            title: '时间',
            dataIndex: 'time',
            key: 'time',
        },
        {
            title: '式子',
            dataIndex: 'formula',
            key: 'formula',
        },
        {
            title: '操作',
            dataIndex: 'action',
            render: (text, record) => (
                <div>
                    <button onClick={() => this.reCalculator(record.formula)}>继续计算</button>
                    <button onClick={() => this.childDelete(record.key)}>删除</button>
                </div>
            ),
        }
    ];
    render() {
        return(
            <div>
                <Table dataSource={this.props.dataSource} columns={this.columns} />
            </div>
        )
    }
}

export default History;